package com.example.shopping.login.Util;

import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JwtUtil {
    public static String make(Object user){
        //数据
        //List users = usersDao.getlist("admin","123456");
        //失效时间...
        Date now=new Date();
        long haomiao=now.getTime() + 3600 * 1000;
        Date expire=new Date(haomiao);
        //生成
        JwtBuilder builder= Jwts.builder()
                .setIssuedAt(now) //令牌发放时间
                .setExpiration(expire) //令牌过期时间
                .claim("login",user) //自定义数据
                .signWith(SignatureAlgorithm.HS256,"shopping");
        //设置签名 用HS256 算法 设置密钥
        String token=builder.compact();
        System.out.println(token);
        return token;
    }
}
